package observer;

import java.util.LinkedList;
import java.util.Random;

public class Senzor implements Subject{
	private LinkedList<Observer> obs =new LinkedList<Observer>();
	private int valCurenta=0;
	
	//Adauga un Observer
	public void addObserver(Observer o){
		obs.add(o);
	}

	//Sterge un Observer
	public void removeObserver(Observer o) {
		obs.remove(o);
	}

	//Notifica Observerii
	public void notifyObserver(){
		java.util.Iterator<Observer> i = obs.iterator();
		while(i.hasNext()){
			Observer o = (Observer) i.next();
			o.upDate(this);
		}
	}
	
	//Genereaza un numar aleator
	public void generare(){
		Random serieRandom=new Random();
		valCurenta=serieRandom.nextInt(80);
		notifyObserver();
	}
	
	//Returneaza valoarea curenta
	public int getVal() {
		return valCurenta;
	}
}
